package com.yanqu.road.server.gameplayer.module.activity.tomb.service;

import com.google.protobuf.InvalidProtocolBufferException;
import com.yanqu.road.pb.syncMessage.SyncMessage;
import com.yanqu.road.pb.tomb.Tomb;
import com.yanqu.road.server.game.service.IGameServiceCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.tomb.TombMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.sync.message.SyncResponse;

public class TombNotifyPushServiceCmd implements IGameServiceCommand {

    @Override
    public SyncResponse execute(SyncMessage.Request request) throws InvalidProtocolBufferException {
        SyncResponse syncResponse = new SyncResponse();
        Tomb.TombNotifyPushCrossToGameReq resp = Tomb.TombNotifyPushCrossToGameReq.parseFrom(request.getDataBytes());
        Tomb.TombNotifyPush.Builder messageBuilder = resp.getResp().toBuilder();

        for (GamePlayer gamePlayer : GamePlayerMgr.getAllOnlinePlayer()) {
            int groupId = GameUnionActivityGroupMgr.getGroupId(TombMgr.getActivityInfo().getActivityId(), gamePlayer.getUserId());
            if(groupId != messageBuilder.getGroupId()){
                continue;
            }
            gamePlayer.sendPacket(ClientProtocol.U_TOMB_NOTIFY_PUSH, messageBuilder);
        }

        return syncResponse;
    }
}
